package com.web.customers;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import com.domain.Customer;
import com.service.CustomerService;
import com.util.AuthenticateHttpServlet;

@WebServlet("/Customer/Add")
public class CustomerAddController extends AuthenticateHttpServlet{

	/**
	 * 
	 */
	private static final long serialVersionUID = 1L;

	protected void post(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
		CustomerService model = new CustomerService();

		Customer customer = new Customer(req.getParameter("customer_id"),
				req.getParameter("firstName"), req.getParameter("lastName"),req.getParameter("sex"),req.getParameter("package_id"),
				req.getParameter("employee_id"),Integer.parseInt(req.getParameter("age")),Integer.parseInt(req.getParameter("height")),Integer.parseInt(req.getParameter("weight")));

		boolean result = model.addCustomer(customer);
		if (result){
			req.getRequestDispatcher("../Customer/List").forward(req,
					resp);		
			}else{
			req.getRequestDispatcher("/WEB-INF/jsp/CustomerAddFailed.jsp").forward(req, resp);
		}
	}
}

